package com.blood.modules.system.controller;

import com.blood.core.annotation.Idempotent;
import com.blood.core.resp.GlobalResultStatus;
import com.blood.core.resp.PageResult;
import com.blood.core.resp.ResponseResult;
import com.blood.core.util.bean.ListUtils;
import com.blood.modules.system.dto.req.SysUserRolePageReq;
import com.blood.modules.system.dto.req.SysUserRoleReq;
import com.blood.modules.system.dto.req.SysUserRoleSaveReq;
import com.blood.modules.system.dto.resp.SysUserRoleInfoResp;
import com.blood.modules.system.dto.resp.SysUserRolePageResp;
import com.blood.modules.system.service.ISysUserRoleService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户角色Controller
 *
 * @author daoren
 * @date 2022-11-23 10:32:43
 */
@Api(value = "用户角色", tags = "用户角色")
@ApiSort(999)
@RestController
@RequestMapping("/sys/role")
public class SysUserRoleController {

    /**
     * 用户角色服务.
     */
    @Autowired
    private ISysUserRoleService sysUserRoleService;

    /**
     * 分页查询列表
     *
     * @param req
     * @return 分页数据
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "用户角色列表-分页")
    public ResponseResult<PageResult<SysUserRolePageResp>> pageList(@RequestBody SysUserRolePageReq req) {
        return sysUserRoleService.pageList(req);
    }

    /**
     * 获取.
     *
     * @return 列表信息
     */
    @ApiOperation(value = "获取用户角色列表信息")
    @PostMapping(value = "/getListInfo")
    public ResponseResult<List<SysUserRoleInfoResp>> getListInfo() {
        return GlobalResultStatus.SUCCESS.toResult().response(ListUtils.copyProperties(sysUserRoleService.queryList(), SysUserRoleInfoResp.class));
    }

    /**
     * 添加.
     *
     * @param req 保存参数
     * @return 添加结果
     */
    @ApiOperation(value = "添加用户角色信息")
    @PostMapping(value = "/add")
    @Idempotent
    public ResponseResult<Void> add(@RequestBody @Validated SysUserRoleSaveReq req) {
        return sysUserRoleService.saveInfo(req);
    }

    /**
     * 修改.
     *
     * @param req 修改参数
     * @return 修改结果
     */
    @ApiOperation(value = "修改用户角色信息")
    @PostMapping(value = "/update")
    @Idempotent
    public ResponseResult<Void> update(@RequestBody @Validated SysUserRoleSaveReq req) {
        return sysUserRoleService.updateInfo(req);
    }

    /**
     * 根据id获取详情
     *
     * @param id
     * @return 详情
     */
    @GetMapping("/findDetailById")
    @ApiOperation(value = "获取用户角色详情")
    public ResponseResult<SysUserRoleInfoResp> findDetailById(@ApiParam(value = "id", type = "String") @RequestParam("id") String id) {
        return sysUserRoleService.findDetailById(id);
    }
}
